package cn.dfun.demo.scdemo.ali.payment.controller;

import cn.dfun.demo.scdemo.common.entity.CommonResult;
import cn.dfun.demo.scdemo.common.entity.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class PaymentController {
    @Value("${server.port}")
    private String serverPort;
    public static HashMap<Long, Payment> hashMap = new HashMap<>();
    // 模拟dao处理
    static {
        hashMap.put(1L, new Payment(1L, "1111111"));
        hashMap.put(2L, new Payment(1L, "2222222"));
        hashMap.put(3L, new Payment(1L, "3333333"));
    }

    @GetMapping(value="/payment/nacos/{id}")
    public String getById(@PathVariable("id") Integer id) {
        return "nacos registry, serverPort: " + serverPort;
    }

    @GetMapping(value="/payment/{id}")
    public CommonResult<Payment> getById(@PathVariable("id") Long id) {
        Payment payment = hashMap.get(id);
        String msg = "port:" + serverPort;
        CommonResult<Payment> result = CommonResult.success(msg, payment);
        return result;
    }
}
